﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HYBYSoft.Company.Models;

namespace HYBYSoft.Company.WebSite.Controllers
{
    public class ContactController : Controller
    {
        /// <summary>
        /// 数据库上下文
        /// </summary>
        CompanySiteEntities _db = new CompanySiteEntities();

        /// <summary>
        /// 联系我们首页
        /// Get提交
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            //获取公司信息和所有联系人
            var companyInfo = (from companies in _db.Companies
                               join link in _db.Linkmen on companies.CompanyID equals link.CompanyID into Linkmanlist
                               select new CompanyAndLinkmanRelation
                               {
                                   CompanyID = companies.CompanyID,
                                   Name = companies.Name,
                                   Corporation = companies.Corporation,
                                   Address = companies.Address,
                                   TelFirst = companies.TelFirst,
                                   TelSecond = companies.TelSecond,
                                   TelThird = companies.TelThird,
                                   Scale = companies.Scale,
                                   Postcode = companies.Postcode,
                                   Fax = companies.Fax,
                                   Type = companies.Type,
                                   Trade = companies.Trade,
                                   Business = companies.Business,
                                   Honor = companies.Honor,
                                   E_mail = companies.E_mail,
                                   City = companies.City,
                                   Description = companies.Description,
                                   Linkmen = (List<Linkman>)Linkmanlist
                               }).First();
            return View(companyInfo);
        }
    }
}
